package com.auicyh.oil;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableStringBuilder;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;

import com.auicyh.tylb.dialog.DialogCustomFragment;
import com.auicyh.tylb.dialog.DialogPerHintFragment;
import com.auicyh.tylb.dialog.DialogQrCodeFragment;
import com.auicyh.tylb.inter.DialogItemCallBacks;
import com.auicyh.tylb.model.ImageTextModel;
import com.auicyh.tylb.utils.LogUtils;
import com.auicyh.tylb.utils.ScreenUtil;
import com.auicyh.tylb.utils.StringUtils;


/**
 * @author Ocean 我想测试一下代码审核
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = findViewById(R.id.main_dialog_bt);
        button.setOnClickListener(this);
        findViewById(R.id.main_qrcode_dialog_bt).setOnClickListener(this);
        findViewById(R.id.main_grid_view_bt).setOnClickListener(this);
        findViewById(R.id.main_hint_bt).setOnClickListener(this);
        LogUtils.e(true, "像素" + ScreenUtil.getPx(this, 20) + "\t " + ScreenUtil.dip2px(this, 20));
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    @Override
    public void onClick(View v) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        switch (v.getId()) {
            case R.id.main_dialog_bt:
                // 简单对话框
                float inch = ScreenUtil.getScreenInch(MainActivity.this);
                LogUtils.e(true, "" + inch);
                DialogCustomFragment dialogCustomFragment = DialogCustomFragment.
                        newInstance("s义UI控件；熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android熟练掌握Android");
                dialogCustomFragment.setGravity(Gravity.START);
                ft.add(dialogCustomFragment, "show");
                // 注意这里使用commitAllowingStateLoss()
                ft.commitAllowingStateLoss();
                break;

            case R.id.main_qrcode_dialog_bt:
                /// DialogQrCodeFragment qrCodeFragment = DialogQrCodeFragment.newInstance("ssid熟练掌握Android熟练掌握And");
                DialogQrCodeFragment qrCodeFragment = new DialogQrCodeFragment();
                qrCodeFragment.setQrCodeStr("我的大北京");
                ft.add(qrCodeFragment, "show");
                // 注意这里使用commitAllowingStateLoss()
                ft.commitAllowingStateLoss();
                break;
            case R.id.main_grid_view_bt:
                DialogPerHintFragment hintFragment = DialogPerHintFragment.newInstance(MainActivity.this, R.string.title, R.string.next);
                ft.add(hintFragment, "hnt");
                hintFragment.setCancelable(false);
                hintFragment.setItemCallBacks(new DialogItemCallBacks() {
                    @Override
                    public void onItemClick(ImageTextModel imageTextModel, int position) {
                        LogUtils.e(true, getString(imageTextModel.getNameRes()));
                    }

                    @Override
                    public void onLongItemClick(ImageTextModel imageTextModel, int position) {

                    }
                });
                ft.commitAllowingStateLoss();
                break;
            case R.id.main_hint_bt:
                DialogCustomFragment dialogFragment = DialogCustomFragment.newInstance("标题", "内容");
                dialogFragment.setDiscolor(true);
                String errorCodeStr = "错误码：" + String.valueOf(456);
                String ss = "dakjdhkasdhiashd" + errorCodeStr;
                SpannableStringBuilder spannableString =
                        StringUtils.setCharColor(ss, ContextCompat.getColor(this, R.color.colorAccent), errorCodeStr);
                dialogFragment.setSpannableString(spannableString);
                if (!isFinishing()) {
                    ft.add(dialogFragment, "dialog_fragment");
                    // 注意这里使用commitAllowingStateLoss()
                    ft.commitAllowingStateLoss();
                }
                break;
            default:

                break;
        }
    }
}
